using DnsClient;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using YDT.EBusines.Models;
using YDT.EBusines.Services;

namespace YDT.EBusines
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();
            builder.Configuration.AddJsonFile("appsettings.json", true, true);

            ConfigurationBuilder builderx = new ConfigurationBuilder();
            builderx.AddJsonFile("appsettings.json", false, true); //动态更新配置服务
            IConfiguration configuration = builderx.Build();
            // 2��������ƷMongoDBѡ��
            builder.Services.Configure<ProductMongoDBOptions>(configuration.GetSection(nameof(ProductMongoDBOptions)));
            builder.Services.AddSingleton<IProductService, ProductService>();
            var app = builder.Build();
            IOptions<ProductMongoDBOptions> options = app.Services.GetRequiredService<IOptions<ProductMongoDBOptions>>();
            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
